<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>流程批量审批定义设置管理</title>
    <#include "/pubHeadStyle.html">
</head>
<body>
<div class="ccpui-tablesize" style="padding:10px;">
    <table id="batchApproval" lay-filter="batchApproval"></table>
</div>
<script type="text/html" id="batchApprovalToolsBar">
    <div class="layui-btn-container">
        <a class="layui-btn layui-btn-sm" lay-event="query">
            <i class="layui-icon layui-icon-search"></i>
            <span>查询</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="add">
            <i class="layui-icon layui-icon-add-1"></i>
            <span>新增</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="edit">
            <i class="layui-icon layui-icon-edit"></i>
            <span>编辑</span>
        </a>
        <a class="layui-btn layui-btn-sm" lay-event="reset">
            <i class="layui-icon layui-icon-refresh"></i>
            <span>重置</span>
        </a>
    </div>
    <form class="layui-form" action="" style="margin-top:10px" lay-filter="template">
        <div class="table-top-filter">
            <div class="table-filter-alone">
                <label class="layui-form-label">流程定义： </label>
                <input type="hidden" id="Q_defKey_SL" name="Q_defKey_SL" class="layui-input" >
                <input type="text" disabled name="Q_subject_S" id="subject" class="layui-input filter-value" placeholder="流程定义"
                       autocomplete="off"/>
                <a class="layui-btn layui-btn-sm " id="assignChoose">选择</a>
            </div>
        </div>
    </form>
</script>
<script type="text/html" id="manageBar">
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-xs" lay-event="detail">明细</a>
</script>
<script>
    layui.config({
        base: serverPath.systemPath + staticPath.systemPath //静态资源所在路径
    }).extend({
        index: 'index' //主入口模块
    }).use(['index','form','common', 'table', 'layer', 'totalFilter','commons'], function () {
        var form = layui.form, layer = layui.layer, totalFilter = layui.totalFilter;
        var table = layui.table;
        var $ = layui.$;
        var setter = layui.setter, common = layui.common;
        var commons = layui.commons;

        var tableH = commons.tabHeight();

        table.render({
            elem: '#batchApproval'
            , url: serverPath.workflowPath + setter.workflowLinkPath + "bpmBatchApproval/list"
            , height: tableH
            , toolbar: '#batchApprovalToolsBar'
            ,defaultToolbar: ['filter', 'print']
            , page: true
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {field: 'subject', title: '流程定义', align: "center"}
                , {field: 'nodeName', title: '节点名称', align: "center"}
                , {fixed: 'right', title: '管理', toolbar: '#manageBar', width: 250, align: 'center'}
            ]]
        });
        totalFilter.init('batchApproval');
        
        //查询选择框
        $(document).off('click','#assignChoose').on("click","#assignChoose",function () {
            parent.layer.open({
                type: 2,
                area: ['950px', '700px'],
                title: ['流程选择'],
                btn:["选择","关闭"],
                skin: 'btn-class',
                content:serverPath.workflowPath+setter.workflowLinkPath +'actDefModel/view/selector',
                yes:function (index,layero) {
                    //获取iframe的body元素
                    var body = parent.layer.getChildFrame('body',index);
                    //得到iframe页的窗口对象
                    var iframeWin = parent.window[layero.find('iframe')[0]['name']];
                    //执行iframe页的showMsg方法
                    $("#subject").val(body.find("input[name=selectedFlowName]").val());
                    $("#triggerFlowKey").val(body.find("input[name=selectedFlowKey]").val());
                    parent.layer.close(index);
                }
            });
        });

        function addOrEdit(type,data){
            layer.open({
                type: 2,
                title: type === 'add' ? "新增" : '编辑',
                area: ['900px', '600px'],
                btn: ['保存', '取消'],
                content: serverPath.workflowPath + setter.workflowLinkPath + "bpmBatchApproval/view/edit" + (type === 'add' ? '' : '?id=' + data),
                skin: 'btn-class',
                yes: function (index, layero) {
                    //获取iframe的body元素
                    var body = layer.getChildFrame('body', index);
                    //得到iframe页的窗口对象
                    var iframeWin = window[layero.find('iframe')[0]['name']];
                    if (body.find("[name='subject']").val()!=""&&body.find("[name='subject']").val()&&body.find("[name='name']").val()!=""&&body.find("[name='name']").val()){
                        var TheId = body.find("[name='id']").val();
                        var nodeId = body.find("[name='nodeId']").val();
                        var nodeName = body.find("[name='name']").val();
                        var modelKey = body.find("[name='modelKey']").val();
                        var subject = body.find("[name='subject']").val();
                        var tableId = body.find("[name='tableId']").val();
                        var fieldJson = [];
                        $.each(body.find("#fieldBody").children("tr"),function (k,v) {
                            var fielddx = {};
                            fielddx.fieldName=body.find("td[name='fieldName']").eq(k).text();
                            fielddx.fieldDesc=body.find("input[name='fieldDesc']").eq(k).val();
                            if (body.find("input[name='isShow']").eq(k).is(":checked")){
                                fielddx.isShow=1;
                            }else {
                                fielddx.isShow=0
                            }
                            fielddx.sn=k+1;
                            fieldJson.push(fielddx);
                        });
                        var data = {id:TheId,nodeId:nodeId,nodeName:nodeName,modelKey:modelKey,subject:subject,tableId:tableId,
                            fieldJson: JSON.stringify(fieldJson)};
                        var url = serverPath.workflowPath + setter.workflowLinkPath + "bpmBatchApproval/save";
                        $.post(url, data, function(result){
                            if (component.filterRecord(result)) {
                                layer.alert(result.msg, function(index1) {
                                    layer.close(index1);
                                    layer.close(index);
                                    table.reload('batchApproval', {
                                        page: {
                                            curr: 1
                                        }
                                    });
                                    totalFilter.init('batchApproval');
                                });
                            } else {
                                layer.alert(result.msg);
                            }
                        }, "json");
                    }else {
                        layer.alert("选择有效数据", function(index1) {
                            layer.close(index1);
                        });
                    }

                }
            })
        }

        //头部监听
        table.on('toolbar(batchApproval)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            var data = checkStatus.data; //获取选中行数据
            switch (obj.event) {
                case 'query':
                    common.tableConditionRender("batchApproval", "template", {where: {}}, false);
                    break;
                case 'add':
                    addOrEdit('add');
                    break;
                case 'edit':
                    if (data.length === 0){
                        layer.msg("还没有选择，请选择一项进行编辑！",{time: 2500, icon:5});
                        return false;
                    }
                    if (data.length !== 0 && data.length !== 1){
                        layer.msg("已经选择了多项，请选择一项进行编辑！",{time:2500,icon:5});
                        return false;
                    }
                    addOrEdit('edit',data[0].id);
                    break;
                case 'reset':
                    common.tableConditionRender("batchApproval","template",{where:{}},true);
                    break;
            }
        });

        //监听行工具事件
        table.on('tool(batchApproval)', function (obj) {
            var data = obj.data;
            switch (obj.event) {
                //删除
                case 'del':
                    layer.confirm('确定删除当前数据吗？',{skin: 'btn-class'}, function () {
                        $.ajax({
                            url: serverPath.workflowPath + setter.workflowLinkPath + 'bpmBatchApproval/delete',
                            type:'post',
                            dataType: 'json',
                            data: {id: data.id},
                            success: function (data) {
                                //提示消息
                                layer.alert("删除成功！",{skin: 'btn-class'});
                                //执行重载
                                table.reload('batchApproval', {
                                    page: {
                                        curr: 1
                                    }
                                });
                                totalFilter.init('batchApproval');
                            }
                        })
                    });
                    break;
                //编辑
                case 'edit':
                    addOrEdit('edit',data.id);
                    break;
                //明细
                case 'detail':
                    layer.open({
                        type: 2,
                        title: '明细',
                        shade: 0.3,
                        area: ['600px', '300px'],
                        content:  serverPath.workflowPath + setter.workflowLinkPath + "bpmBatchApproval/view/get?id="+data.id

                    });
                    break;
            }
        });
    })
</script>
</body>
</html>
<!--<link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>-->
<link rel="stylesheet" href="${ctx}/systemStatic/style/admin.css">